feat(chameleon): Chameleon-7B Thor FP8 and Orin SM87 INT8/QuaRot frontends - #166
feat(chameleon): Chameleon-7B Thor FP8 and Orin SM87 INT8/QuaRot frontends#166DXICM wants to merge 7 commits into
Conversation
|
Thank you for contributing the complete Chameleon-7B Thor FP8 and Orin SM87 frontends. The responsibilities of the model layer, pipelines, and hardware backends are generally separated clearly, and we did not find an existing model being redirected to the Chameleon runtime. Codex reviewed this PR against FlashRT's long-term maintenance standards. We recommend addressing the following items after #165 has been corrected and merged. Required changes
Pre-merge checklist
Please also refer to the repository's PR Review Checklist and Adding a New Model guides. This is a Codex-assisted maintainability review. The architecture is moving in a reasonable direction; the dependency order, model build isolation, input boundaries, and third-party distribution requirements need to be completed before these hardware frontends are suitable for long-term support on |
…SM110 fail-fast, max_new_tokens contract, VQGAN license, contract tests Address the flashrt-project#166 maintainability review: - Thor prompt-pad boundary: allocation floors capacity to a multiple of 16 and set_prompt validates the PADDED length, so a non-aligned max_seq can never let pad-to-16 overshoot the buffers/KV cache. - Thor hardware gate: ChameleonTorchFrontendThor checks device capability before checkpoint load / CUDA allocation; documented dev override FLASHRT_CHAMELEON_THOR_FORCE=1. - Generation boundary: Thor generate_greedy and Orin generate both reject negative max_new_tokens (ValueError); Orin returns an empty result for zero instead of running prefill and emitting one token. - VQGAN licensing: vendored Meta Chameleon files now carry the full Chameleon Research License (LICENSE) plus a NOTICE recording provenance (incl. the upstream CompVis MIT attribution), the inference-only modifications, and a compatibility notice. Documented in chameleon_usage.md. - Contract tests (tests/test_chameleon_contracts.py): registry + lazy-import, load_model chameleon redirect, Thor/Orin hardware fail-fast, prompt padding bounds, and generation-parameter bounds.
a57db4c to
193797e
Compare
|
Thanks for the review. The branch has been rebased onto the corrected #165 head and all six items are addressed in 193797e; once #165 merges, this PR will be rebased onto 1. Dependency/rebase — rebased onto the corrected #165 head; will rebase onto 2. Thor prompt-padding capacity boundary — capacity is now floored to a multiple of 16 at allocation ( 3. SM110 fail-fast — 4. Orin generation-parameter boundary — 5. VQGAN licensing — the vendored files are from Meta Chameleon ( 6. Contract tests — Production Orin re-test of this branch (build matrix + contract tests) is queued; results will be reported here. |
|
Production re-test of 193797e on Jetson Orin (sm_87, CUDA 12.2, torch 2.3.0) — all green:
Outstanding: the VQGAN license policy decision flagged above, and the #165 merge + rebase onto |
Standalone Chameleon-7B (image+text) prefill/decode frontend for Jetson AGX Thor: - flash_rt/models/chameleon/pipeline_thor.py: 32-layer Chameleon forward with runtime dynamic per-tensor FP8 (fused quantize kernels), cuBLASLt per-shape autotune, selective L31 ffn_down clamp, optional AWQ V-proj and NVFP4 FFN tiers, CUDA-graph capture with re-embed before replay, and incremental KV-cache decode over fmha_fp16_causal_br. - Vendored Meta Chameleon VQ-GAN tokenizer (flash_rt/models/chameleon/vqgan, Meta Chameleon License headers retained; see the package docstring) with an eager default path and an opt-in TensorRT engine backend (hardware/thor/vqgan_trt_backend.py). - ChameleonTorchFrontendThor (frontends/torch/chameleon_thor.py): checkpoint_dir is a required argument with a clear error when missing; declarative weight spec in _chameleon_thor_spec.py. - hardware/thor/attn_backend_chameleon.py: CUTLASS causal FMHA backend with optional FA4 fast path, loading libfmha_fp16_causal.so from the package directory.
Jetson AGX Orin (SM87) Chameleon-7B path aligned with the upstream rtx_sm87 naming: - flash_rt/models/chameleon/pipeline_rtx.py: one chameleon_forward serving prefill and decode on the SM80 CUTLASS INT8/INT4 rowwise GEMMs with QuaRot-Hadamard rotations (correctness requirement, not an optimization) and the ffn_down clamp on the last 4 layers (FP16 65504 overflow guard). - _chameleon_quant.py: INT8/INT4 weight quantization + Hadamard packing from the BF16 checkpoint. - _chameleon_spec.py: declarative weight spec with an inlined, Chameleon-specific _llm_block (no bias terms, no FP8 scales). - ChameleonTorchFrontendRtxSm87 (chameleon_rtx_sm87.py): set_prompt / prefill / decode_step / generate, FLASHRT_CHAMELEON_SM87_FORCE escape hatch. - hardware/rtx/attn_backend_chameleon.py: FA2 fwd_fp16_causal is mandatory for decode (bottom-right causal semantics); the backend raises rather than falling back to a top-left cuBLAS mask, which would be silently wrong. Runtime numbers (21.07 tok/s, 16/16 bit-identical greedy vs HF BF16) were measured on Orin hardware in the derivative repo and still need SM87 validation here.
- Register ("chameleon", "torch", "thor") and ("chameleon", "torch",
"rtx_sm87") in _PIPELINE_MAP and allow the SM87 key in _SM87_ALLOWED.
- api.load_model redirect for config="chameleon" (chat-style VLM, same
pattern as qwen3_vl): raises NotImplementedError pointing at the two
direct-instantiation frontends.
- tests/test_chameleon_thor_vqgan_backend.py: eager-vs-TRT VQGAN backend
contract test.
- scripts/: bench_chameleon_thor.py, check_chameleon_thor_precision.py,
profile_chameleon_thor.py, chameleon_orin_check.py (Gate-1 harness) and
build_vqgan_trt.py (now driven by the vendored
flash_rt.models.chameleon.vqgan package); HF BF16 reference rows use
transformers' ChameleonForConditionalGeneration directly.
- examples/thor/chameleon_quickstart.py + README entry,
benchmarks/chameleon_thor_latency.py.
- Docs: chameleon_usage.md, chameleon_thor_sm110.md and
chameleon7b_rtx_sm87.md; Chameleon rows in USAGE.md, README.md and
docs/benchmark_comparison.md.
Thor numbers were measured on Jetson AGX Thor (sm_110). All SM87 runtime
numbers in the Orin doc (21.07 tok/s, 16/16 bit-identical greedy vs HF
BF16) come from Orin hardware in the derivative repo and still need SM87
validation in this tree.
- FLASHRT_RYNNVLA2_FP4_LAYERS -> FLASHRT_CHAMELEON_FP4_LAYERS (the env var was inherited from the RynnVLA port with its old name) - replace "001"/"002"/"vendor bf16" comments with plain Chameleon / HF-reference wording in pipeline_thor.py and chameleon_thor.py
- Add #!/usr/bin/env python3 shebangs to 4 scripts and 1 benchmark - Rename _chameleon_spec.py to _chameleon_rtx_sm87_spec.py (hardware suffix per adding_new_model.md convention) and update the import - Add config="chameleon" to docs/stable_api.md (config enum, redirect bullet, resolve_pipeline_class registration) - Translate docs/chameleon_thor_sm110.md from Chinese to English - Remove all internal "derivative repo" / "RynnVLA" provenance references from both engineering docs (42 occurrences) - Move fp4_chameleon_layer16 benchmark from tests/ to benchmarks/ (it has no test_ functions; misfiled in the kernels branch)
…SM110 fail-fast, max_new_tokens contract, VQGAN license, contract tests Address the flashrt-project#166 maintainability review: - Thor prompt-pad boundary: allocation floors capacity to a multiple of 16 and set_prompt validates the PADDED length, so a non-aligned max_seq can never let pad-to-16 overshoot the buffers/KV cache. - Thor hardware gate: ChameleonTorchFrontendThor checks device capability before checkpoint load / CUDA allocation; documented dev override FLASHRT_CHAMELEON_THOR_FORCE=1. - Generation boundary: Thor generate_greedy and Orin generate both reject negative max_new_tokens (ValueError); Orin returns an empty result for zero instead of running prefill and emitting one token. - VQGAN licensing: vendored Meta Chameleon files now carry the full Chameleon Research License (LICENSE) plus a NOTICE recording provenance (incl. the upstream CompVis MIT attribution), the inference-only modifications, and a compatibility notice. Documented in chameleon_usage.md. - Contract tests (tests/test_chameleon_contracts.py): registry + lazy-import, load_model chameleon redirect, Thor/Orin hardware fail-fast, prompt padding bounds, and generation-parameter bounds.
193797e to
46770a0
Compare
Summary
Adds standalone Chameleon-7B image/text VLM frontends for Jetson Thor SM110 and Jetson Orin SM87. This PR depends on #165 and must be merged after it.
The branch has been rebased onto current
mainand now contains only the model-layer delta: nocsrc/or CMake files from #165 are included.Frontends
load_model(config="chameleon")redirects callers to the direct chat-style frontend API.License boundary
The Research-License Meta VQGAN implementation, license, and notice were removed from the package.
Both Thor eager tokenization and the TensorRT builder now use the Apache-2.0 Transformers
ChameleonVQVAEimplementation and load onlymodel.vqmodel.*tensors from the user-provided safetensors checkpoint. Loading is strict, shard-selective, and covered by a synthetic checkpoint test. The adapter supports both the Transformers 4.43 tuple output and newerimage_tokensmodel output.A
chameleonoptional dependency group now installs the required Torch, safetensors, Transformers, and Pillow runtime dependencies.Runtime contracts
max_seq < 16before allocation; pad-to-16 can no longer create a zero-capacity runtime.flash_rt_fp4handling catches only the exact missing module, not arbitrary import/link errors.Validation
24 passed.3 passed.93 passed.git diff --checkandpyproject.tomlparsing pass.csrc/or CMake changes.Merge order
mainif GitHub reports any new base movement.